//
//  SleepBarChartView.swift
//  MYModule
//
//  Created by HFY on 2022/10/31.
//

import UIKit
import MYModule

open class SleepBarRoundChartView: BarRoundChartView {
    
    public override func makeUI() {
        super.makeUI()
        cornerRadius = 18.0
    }
    
    public func setType(_ type:SleepDataCompareType){
        self.backgroundColor = type.backgroundColor
        
        let normarText = BluetoothManager.shared.deviceState == .connected ? nil : "--"
        self.titleLabel.attributedText = type.titleAttributedText(normarPercentStr: normarText)
        let profile  = UserCacheManagement.userInfo()
        let sex = profile.sex.localeName
        
        self.subTitleLabel.attributedText = type.subTitleAttributedText(text: "sleep_compare_male_users_content".language(with: [sex]), textColor: UIColor.assist_A9A9A9, font: Fonts.systemFont(ofSize: 12))
        
        
        let config = DFBarChartViewConfig.init(xAxisLabelFont: Fonts.systemFont(ofSize: 10),
                                               xAxisLabelTextColor: type.xAxisLabelTextColor,
                                               xAxisLineColor: type.xAxisLabelColor, highlightPerTapEnabled: false)
        self.chartView.setConfig(config)
        self.chartView.setXAxis(valueFormatter: DataCompareAxisValueFormatter(axisValueArray: type.xAxisValues))
        
        
//        type.barHightLightColor
        self.chartView.setData(type.data.map{Double($0)},
                               barColor: type.barNormalColor,
                               barHighLichtColor: type.barHightLightColor, showEmpty: true)
        
        print(type.highlightIndex)
        self.chartView.showMarkerViewOfBar(index: type.highlightIndex)
        
       
    }

 
}
